"""
Case Type   : 资源池化
Case Name   : 缩容工具gs_dropnode -U USER -G GROUP -h hostlist  指定用户错误
Create At   : 2024.10
Owner       : chen
Description :
    1.执行缩容，指定用户为root
    gs_dropnode -U USER -G GROUP -h hostlist
    2.指定用户为非集群用户
Expect      :
    1、合理报错
    2、合理报错
"""

import os
import unittest
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

class SharedStorage(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_node = Node('PrimaryDbUser')
        self.db_host = Node('Standby2DbUser').db_host

    def test_shared_storage(self):
        text = '-----step1: 执行缩容，指定用户为root' \
            ' expect: 合理报错-----'
        self.log.info(text)
        
        cmd = f'''source {macro.DB_ENV_PATH}; \
            gs_dropnode -U root -G root -h {self.db_host}'''
        self.log.info(cmd)
        res = self.pri_node.sh(cmd).result()
        self.log.info(res)
        self.assertIn('The user root is not the cluster installation user',
        res, text + '失败')

        text = '-----step2: 指定用户为非集群用户 expect: 合理报错-----'
        self.log.info(text)
        cmd = f'''source {macro.DB_ENV_PATH}; \
            gs_dropnode -U case002 -G case002 -h {self.db_host}'''
        self.log.info(cmd)
        res = self.pri_node.sh(cmd).result()
        self.log.info(res)
        self.assertIn('User case002 does not exist',
        res, text + '失败')

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')